
import UIKit
import QuartzCore
class XWSpeedViewController: UIViewController {

    
    @IBOutlet weak var XWPointerImageView: UIImageView!
    
    @IBOutlet weak var XWPointerBackView: UIView!
    
    @IBOutlet weak var XWDownloadLabel: UILabel!
    
    @IBOutlet weak var XWUploadLabel: UILabel!
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        showUI()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    @IBAction func XWBackButtonClick(_ sender: UIButton) {
        dismiss(animated: true, completion: nil)
    }
    
    @IBAction func XWTestButtonClick(_ sender: UIButton) {
        sender.isUserInteractionEnabled = false
        var radian = -(Double.pi/4*3)
        let olCenter = CGPoint(x: XWPointerBackView.frame.size.width/2.0, y: XWPointerBackView.frame.size.height/2.0)
        XWPointerImageView.layer.anchorPoint = CGPoint(x: 0.5, y: 0.8)
        XWPointerImageView.center = olCenter
        XWPointerImageView.transform = CGAffineTransform(rotationAngle: radian)
        let random  = (arc4random() % 5 + 2)
        UIView.animate(withDuration: TimeInterval(random)) {
            radian = radian + Double.pi/Double.pi
            printLog(random)
            self.XWPointerImageView.transform = CGAffineTransform(rotationAngle: radian)
        } completion: { finished in
            let vc = XWSpeedResultViewController()
            PresentViewController(vc)
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
                self.XWPointerImageView.transform = CGAffineTransform(rotationAngle: 0)
            }
            sender.isUserInteractionEnabled = true
        }
    }
    
    @IBAction func XWMapButtonClick(_ sender: UIButton) {
        let vc = XWMapViewController()
        PresentViewController(vc)
    }
    
    @IBAction func XWScanButtonClick(_ sender: UIButton) {
        let vc = XWScanViewController()
        PresentViewController(vc)
    }
}
extension XWSpeedViewController{
    private func showUI() {
        XWDataStateTool.shareManger.XWDownloadLabl = XWDownloadLabel
        XWDataStateTool.shareManger.XWUploadLabel = XWUploadLabel
    }
}
